package libs.yzx.zaza;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

/**
 * Created by Administrator on 2016/7/12
 */
public class JNIActivity extends AppCompatActivity {

    private String byJniString;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_jni);
        testJniUtil();
    }

    public void click1(View view){
        setImageGray();
        Toast.makeText(this, "图片变黑白", Toast.LENGTH_SHORT).show();
    }

    public void click2(View view){
        Toast.makeText(this, "CPU ABI : " + getCPUABI(), Toast.LENGTH_SHORT).show();
    }

    public void click3(View view){
        exceptionTest();
        Toast.makeText(this, "c++错误处理 , 看log", Toast.LENGTH_SHORT).show();
    }


    /** 图片变成黑白 */
    private void setImageGray(){
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inMutable = true;
        options.inSampleSize = 2;
        Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher, options);
        bmp(bmp);
        ImageView iv = new ImageView(this);
        iv.setImageBitmap(bmp);
        setContentView(iv);
    }


    //===============================================


    /* 变成黑白照片 */
    private native static void bmp(Bitmap bmp);
    /* 获取cpu的ABI类型 */
    private native static String getCPUABI();
    /* 测试c++的错误处理 */
    private native static void exceptionTest();
    /* 测试jniUtil.cpp */
    private native static void testJniUtil();

    static { System.loadLibrary("main");}


    public static void callByJni(String str){
        Toast.makeText(AAA_Application.app, str, Toast.LENGTH_SHORT).show();
    }
}
